import 'package:device_info_plus/device_info_plus.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shouyin_app/common/utils/utils.dart';

class PermissionUtils {
  ///检查是否有权限
  ///[permission] 权限
  ///return 是否有权限
  static Future<bool> applyPhotos() async {
    // var status = await permission.status;
    // if (status.isDenied) {
    //   return false;
    // } else if (status.isGranted) {
    //   return true;
    // } else if (status.isPermanentlyDenied) {
    //   // 永久拒绝，仅支持Android
    //   return false;
    // } else if (status.isRestricted) {
    //   //仅支持iOS
    //   return false;
    // } else {
    //   return false;
    // }
    if(DeviceUtil.isAndroid) {
      final deviceInfo = await DeviceInfoPlugin().androidInfo;
      if (deviceInfo.version.sdkInt > 32) {
        Map<Permission, PermissionStatus> statuses = await [
          Permission.videos,
          Permission.audio,
          Permission.photos,
          Permission.camera,
        ].request();





        return !statuses.containsKey(false);
      } else {
        Map<Permission, PermissionStatus> statuses = await [
          Permission.storage,
          Permission.camera,
        ].request();
        return !statuses.containsKey(false);
      }
    } else if(DeviceUtil.isIOS) {
      Map<Permission, PermissionStatus> statuses = await [
        Permission.photos,
        Permission.camera,
      ].request();
      return !statuses.containsKey(false);
    }
    return false;
  }
}